package com.ofa.service.impl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ofa.base.Pagination;
import com.ofa.dao.RoleDao;
import com.ofa.dao.UserRoleDao;
import com.ofa.entity.Role;
import com.ofa.entity.UserRole;
import com.ofa.service.RoleService;


@Service(value="roleService")
public class RoleServiceImpl implements RoleService {
	
	private RoleDao roleDao;
	
	private UserRoleDao userRoleDao;
	

	
	public Role get(Serializable id) {
		return roleDao.get(id, Role.class);
	}

	public void delete(Serializable id) {
		roleDao.delete(id, Role.class);
	}

	public void save(Role entity) {
		roleDao.save(entity);
	}

	public void update(Role entity) {
		roleDao.update(entity);
	}

	public Pagination<Role> queryRoles(Role role, int firstResult, int maxResults){
		return roleDao.queryRoles(role, firstResult, maxResults);
	}
	
	public void delete(List<Serializable> ids){
		List<Serializable> list = new ArrayList<Serializable>();
		for(int i=0; i<ids.size(); i++){
			Serializable id = ids.get(i);
			int d = Integer.parseInt(id.toString());
			list.add(d);
		}
		roleDao.delete(list, Role.class);
	}
	
	public List<UserRole> queryRolesOfUser(Integer userId){
		return userRoleDao.queryRolesOfUser(userId);
	}
	
	public void save(UserRole userRole){
		userRoleDao.save(userRole);
	}
	
	
	public RoleDao getRoleDao() {
		return roleDao;
	}
	@Autowired
	public void setRoleDao(RoleDao roleDao) {
		this.roleDao = roleDao;
	}

	public UserRoleDao getUserRoleDao() {
		return userRoleDao;
	}
	@Autowired
	public void setUserRoleDao(UserRoleDao userRoleDao) {
		this.userRoleDao = userRoleDao;
	}
	
}
